/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dp.model;

import com.dp.utils.HibernateUtil;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author hisik
 */
public class ArticlesDao extends AbstractDao<Articles> implements IBaseDao<Articles> {
    
    private static ArticlesDao articlesDao;

    public static ArticlesDao getInstance() {
        if(articlesDao == null)
            articlesDao = new ArticlesDao();
        return articlesDao;
    }
    
    public List<Articles> getArticlesByName(String name) {
        
        List<Articles> list = null;
        Session session = null;
        try {
        
            session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();

            Query query = session.createQuery("select a from Articles a where a.articleName like :name ");
            query.setParameter("name", name);

            list = (List<Articles>)query.list();
            
        } catch (Exception ex) {
            
        } finally {
            if(session != null) {
                session.flush();
                session.close();
            }
        }
        
        return list;
    }
}
